package com.emns.web.mobile;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.emns.pojo.Yuedu;
import com.emns.service.mobile.YueduMobileService;
import common.PageInfo;

@Controller
@RequestMapping(value = "/yueduMobile")
public class YueduMobileController {

	@Autowired
	YueduMobileService yms;

	// 查找分页悦读数据
	@RequestMapping(value = "/queryPage")
	public void queryPage(Model model,
			@RequestParam(required = false) Integer pageNo,
			@RequestParam(required = false) Integer pageSize,
			@RequestParam(required = false) Integer fLanmu,
			@RequestParam(required = false) Integer sLanmu,
			@RequestParam(required = false) String keyWord) {
		PageInfo<Yuedu> pageInfo = null;
		String errMsg = "";
		String errCode = "";
		if (pageNo == null || pageSize == null) {
			errCode = "1";
			errMsg = "缺少参数:pageNo或pageSize";
		} else if (fLanmu == null || sLanmu == null) {
			errCode = "1";
			errMsg = "缺少参数:fLanmu或sLanmu";
		} else {
			errCode = "0";
			errMsg = "查询成功";
			pageInfo = new PageInfo<Yuedu>();
			pageInfo.setPageNum(pageNo);
			yms.queryPageAll(keyWord, fLanmu, sLanmu, pageInfo);
		}
		model.addAttribute("errorCode", errCode);
		model.addAttribute("errorMessage", errMsg);
		model.addAttribute("info", pageInfo);
	}

	@RequestMapping(value = "/querySingle")
	public void queryById(Model model,
			@RequestParam(required = true) Integer yueduId,
			@RequestParam(required = true) Integer commentUserId) {
		Map<String, Object> map = yms.getYueduById(yueduId, commentUserId);
		model.addAttribute("errorCode", "0");
		model.addAttribute("errorMessage", "查询成功");
		model.addAttribute("info", map);
	}
}
